import { platformTypeName } from '@/utils/config';

const statesOptions = [
  { label: '待登记', value: '0' },
  { label: '待质检', value: '1' },
  { label: '待上架', value: '2' },
  { label: '质检异常', value: '7' },
  { label: '待指派', value: '3' },
  { label: '已指派', value: '4' },
  { label: '退货中', value: '5' },
  { label: '退货成功', value: '9' },
  { label: '退货异常', value: '6' },
  { label: '拒绝退货', value: '8' },
  { label: '商家审核', value: '10' },
  { label: '异常已处理', value: '11' },
]
//表单配置项
const applyFormItemData = {
  'refundOrderSn': {
    itemConfig: {
      name: 'refundOrderSn'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '退货单号',
    }
  },
  'afterSalesType': {
    itemConfig: {
      name: 'afterSalesType'
    },
    elConfig: {
      maxTagCount: 1, 
      formType: 'Select',
      placeholder: '售后类型',
      options: [
        { label: '仅退款', value: '1' },
        { label: '退货退款', value: '0' },
      ]
    }
  },
  'goodsLabel': {
    itemConfig: {
      name: 'goodsLabel'
    },
    elConfig: {
      maxTagCount: 1, 
      formType: 'Select',
      placeholder: '商品类型',
      options: [
        { label: '拿货商品', value: '1' },
        { label: '库存商品', value: '2' },
        { label: '档口商品', value: '4' },
      ]
    }
  },
  'logisticsNo': {
    itemConfig: {
      name: 'logisticsNo'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '退回快递单号',
    }
  },
  'orderSns': {
    itemConfig: {
      name: 'orderSns'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '系统订单号',
      batchInput: true,
      maxInputCount: 50
    }
  },
  'refundStates': {
    itemConfig: {
      name: 'refundStates'
    },
    elConfig: {
      mode: 'multiple', 
      maxTagCount: 1, 
      formType: 'Select',
      placeholder: '退货单状态',
      options: [
        { label: '待登记', value: '10' },
        { label: '部分登记', value: '20' },
        { label: '处理中', value: '30' },
        { label: '处理完成', value: '40' },
        { label: '已取消', value: '50' },
        { label: '待商家处理', value: '0' },
        { label: '待商家收货', value: '3' },
        { label: '商家已拒绝', value: '1' },
      ]
    }
  },
  'outOrderSns': {
    itemConfig: {
      name: 'outOrderSns'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '店铺订单号',
      batchInput: true,
      maxInputCount: 50
    }
  },
  'channelId': {
    itemConfig: {
      name: 'channelId'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '所属渠道',
      options: []
    }
  },
  'storeIds': {
    itemConfig: {
      name: 'storeIds'
    },
    elConfig: {
      formType: 'SearchSupplier',
      placeholder: '供应商',
    }
  },
  'ecStoreNames': {
    itemConfig: {
      name: 'ecStoreNames'
    },
    elConfig: {
      mode: 'multiple', 
      maxTagCount: 1, 
      formType: 'Select',
      placeholder: '所属平台店铺',
      options: []
    }
  },
  'offlineRefund': {
    itemConfig: {
      name: 'offlineRefund'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '是否需线下退款',
      options: [
        { label: '是', value: '1' },
        { label: '否', value: '0' },
      ]
    }
  },
  'applyTime1': {
    itemConfig: {
      name: 'applyTime1'
    },
    elConfig: {
      formType: 'rangTime',
      placeholder: ['申请退货开始时间', '申请退货结束时间'],
      prefix: '申请退货时间',
    }
  },
  'finishTime1': {
    itemConfig: {
      name: 'finishTime1'
    },
    elConfig: {
      formType: 'rangTime',
      placeholder: ['完成开始时间', '完成结束时间'],
      prefix: '完成时间',
    }
  },
}

//表单配置项
const refundFormItemData = {
  'refundApplyOrder': {
    itemConfig: {
      name: 'refundApplyOrder'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '退货单号',
    }
  },
  'uniqueCodes': {
    itemConfig: {
      name: 'uniqueCodes'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '商品唯一码',
      batchInput: true,
      maxInputCount: 50
    }
  },
  'orderSns': {
    itemConfig: {
      name: 'orderSns'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '系统订单号',
      batchInput: true,
      maxInputCount: 50
    }
  },
  'outOrderSns': {
    itemConfig: {
      name: 'outOrderSns'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '店铺订单号',
      batchInput: true,
      maxInputCount: 50
    }
  },
  'ecStoreNames': {
    itemConfig: {
      name: 'ecStoreNames'
    },
    elConfig: {
      mode: 'multiple', 
      maxTagCount: 1, 
      formType: 'Select',
      placeholder: '所属平台店铺',
      options: []
    }
  },
  'receiverName': {
    itemConfig: {
      name: 'receiverName'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '收货人姓名',
    }
  },
  'receiverPhone': {
    itemConfig: {
      name: 'receiverPhone'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '收货人手机号',
    }
  },
  'states': {
    itemConfig: {
      name: 'states'
    },
    elConfig: {
      mode: 'multiple', 
      maxTagCount: 1, 
      formType: 'Select',
      placeholder: '退货状态',
      options: statesOptions
    }
  },
  'type': {
    itemConfig: {
      name: 'states'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '退货类型',
      options: [
        { label: '仓内退货', value: '0' },
        { label: '快递退货', value: '1' },
      ]
    }
  },
  'channelId': {
    itemConfig: {
      name: 'channelId'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '所属渠道',
      options: []
    }
  },
  'storeName': {
    itemConfig: {
      name: 'storeName'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '所属门店',
    }
  },
  'note': {
    itemConfig: {
      name: 'note'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '备注',
    }
  },
  'applyTime': {
    itemConfig: {
      name: 'applyTime'
    },
    elConfig: {
      formType: 'rangTime',
      placeholder: ['申请退货开始时间', '申请退货结束时间'],
      prefix: '申请退货时间',
    }
  },
  'finishTime': {
    itemConfig: {
      name: 'finishTime'
    },
    elConfig: {
      formType: 'rangTime',
      placeholder: ['完成退货开始时间', '完成退货结束时间'],
      prefix: '完成退货时间',
      disabledDate: null,
    }
  },
}


//处理表单数据
export const getFormItem = (optionsData, type) => {
  const arr = [];
  const formData = type == 'apply' ? applyFormItemData : refundFormItemData;
  Object.keys(formData).map(v => {
    if(optionsData && optionsData[v]) {
      if(v == 'channelId') {
        const arr = optionsData[v].map(k => {
          return {
            label: k.channelName,
            value: k.id
          }
        })
        formData[v].elConfig.options = arr;
      }
      if(v == 'ecStoreNames') {
        const arr = optionsData[v].map(k => {
          return {
            label: k.storeName + `【${platformTypeName[k.type]}】`,
            value: k.storeName
          }
        })
        formData[v].elConfig.options = arr;
      }
    }
    arr.push(formData[v]);
  })
  return arr;
}